import Vue from 'vue'
import VueRouter from 'vue-router'
import LayoutPage from '@/layout/index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/',
    name: 'LayoutPage',
    component: LayoutPage,
    children: [
      {
        path: '/home',
        name: 'HomePage',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: '首页',
          keepAlive: false // 是否需要被缓存
        }
      }
    ]
  }
]

const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
const VueRouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace(to) {
  return VueRouterReplace.call(this, to).catch(err => err)
}

const router = new VueRouter({
  routes
})

export default router
